package Atop100.listNode;

import listNodePractice.ListNode;

public class Class19 {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        if (head==null){
            return null;
        }
        ListNode listNode = find(head, n + 1);
        listNode.next=listNode.next.next;
        return  head;
    }

    public  ListNode  find(ListNode head,int n){
        ListNode  remove=null;
        ListNode fast=head,slow=head;
        int i=0;
        while (i<n){
            fast=fast.next;
            i++;
        }
        while (fast!=null){
            fast=fast.next;
            slow=slow.next;
        }
        remove=slow;

        return  remove;


    }


}